package com.jcl.upload.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jcl.upload.dao.FileDao;
import com.jcl.upload.po.CustomFile;
import com.jcl.upload.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/2/3 22:55
 */
@Service
public class FileServiceImpl implements FileService
{
    @Autowired
    private FileDao fileDao;

    @Override
    public void save(CustomFile customFile)
    {
        QueryWrapper<CustomFile> wrapper = new QueryWrapper<>();
        wrapper.eq("file_key", customFile.getFileKey());
        List<CustomFile> files = fileDao.selectList(wrapper);
        //文件存在则修改
        if (files.size() > 0)
        {
            fileDao.update(customFile, wrapper);
        } else
        {
            fileDao.insert(customFile);
        }
    }

    @Override
    public List<CustomFile> check(String key)
    {
        QueryWrapper<CustomFile> wrapper = new QueryWrapper<>();
        wrapper.eq("file_key", key);
        return fileDao.selectList(wrapper);
    }
}
